package com.rj.core.check;

import lombok.Data;

import java.util.function.Consumer;

/**
 * @author Administrator
 */
@Data
public class Dict<V> {
    private V val;
    private V dest;
    private Consumer<AssertorBean> tri;

    public Dict(V val, V dest, Consumer<AssertorBean> tri) {
        this.val = val;
        this.dest = dest;
        this.tri = tri;
    }

    public static <V> Dict<V> of(V val, V dest, Consumer<AssertorBean> tri) {
        return new Dict<>(val, dest, tri);
    }

    public static <V> Dict<V> of(V val, V dest) {
        return new Dict<>(val, dest, null);
    }

    public static <V> Dict<V> of(V val, Consumer<AssertorBean> tri) {
        return new Dict<>(val, null, tri);
    }

    public static <V> Dict<V> of(V val) {
        return new Dict<>(val, null, null);
    }

    /**
     * 触发条件
     **/
    public void trigger(AssertorBean assertorBean) {
        if (tri != null) {
            tri.accept(assertorBean);
        }
    }

    /**
     * 获取转换值
     **/
    public V getDest() {
        return dest != null ? dest : val;
    }
}
